//
//  BaseViewController.m
//  bus
//
//  Created by ygs on 15/6/6.
//  Copyright (c) 2015年 ygs. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController () 

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = BackColor;
    
    // 设置导航栏
    self.automaticallyAdjustsScrollViewInsets=NO;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES; // 支持右滑手势
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
    [self initNavBar];
}
#pragma mark - 导航栏
-(void)initNavBar
{
    _navBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    _navBar.hidden=YES;
    _navBar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_navBar];
    // 导航标题
    _titleLable=[[UILabel alloc]initWithFrame:CGRectMake(40, 20, ScreenWidth-80, 44)];
    _titleLable.backgroundColor=[UIColor clearColor];
    _titleLable.textAlignment=NSTextAlignmentCenter;
    _titleLable.font=[UIFont boldSystemFontOfSize:17];
    _titleLable.textColor=[UIColor blackColor];
    [_navBar addSubview:_titleLable];
    
    UILabel *lineLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 64-.05, ScreenWidth, 0.5)];
    lineLable.backgroundColor = SetColor(0, 0, 0, .3);
    [_navBar addSubview:lineLable];
}
//返回按钮 返回首页
-(void)initNav:(NSString*)title doBack:(BOOL)doBack
{
    _navBar.hidden=NO;
    _titleLable.text=title;
    if (doBack) {
        _backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame=CGRectMake(8, 20+(44-21)/2, 12, 21);
        [_backBtn setNormalImageWith:@"xuanzeshezhang.fw_r2_c2.png"];
        [_backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
        [_backBtn setHitTestEdgeInsets:UIEdgeInsetsMake(-10, -14, -14, -25)];
        [_navBar addSubview:_backBtn];
    }
}
- (void)initNav:(NSString *)title doModel:(BOOL)doModel {
    [self initNav:title doBack:doModel];
    [_backBtn setNormalImageWith:@"选择城市_r1_c1.png"];
    _backBtn.frame=CGRectMake(8, 20+(44-20)/2, 20, 20);
}
- (void)backAction:(UIButton *)btn{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)goLoginView {
    LoginViewController *login = [[LoginViewController alloc] init];
    [self presentViewController:login animated:YES completion:^{
        
    }];
}
#pragma mark -
- (void)navAnimationType:(BOOL)doPush {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.35f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    transition.type = @"push";
    transition.subtype = doPush?kCATransitionFromTop:kCATransitionFromBottom;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
}
- (void)pushViewController:(UIViewController *)viewController {
    [self navAnimationType:YES];
    [self.navigationController pushViewController:viewController animated:NO];
}
- (void)popToRootViewController {
    [self navAnimationType:NO];
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)popViewController {
    [self navAnimationType:NO];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
